<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="openDialog()">打开弹出对话框</button>
    <button onclick="closeDialog()">关闭弹出对话框</button>
    <dialog id="dialog">这是一个对话框元素
    <button onclick="closeDialog()">关闭对话框</button>
    </dialog>
    <script type="text/javascript">
    var dialog = document.getElementById('dialog')
    function openDialog(){
        dialog.showModal()
    }
    function closeDialog(){
        dialog.close()
    }
    dialog.addEventListener('close',function(){
        console.log('弹出对话框被关闭')
    })
    </script>
</body>
</html>
<style>
    dialog::backdrop {
        background-color: rgba(41,107,255,0.4);
    }
</style>